﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Omniscient.Foundation.ApplicationModel.Presentation;
using Omniscient.TimeTracker.Data;
using Omniscient.Foundation.Data;
using Omniscient.Foundation.ApplicationModel;
using Omniscient.Foundation.ApplicationModel.Modularity;

namespace Omniscient.TimeTracker.Presentation
{
    public class TaskBarMenuViewController : IViewController
    {
        public TaskBarMenuViewController()
        {
            // Register extension port
            IExtensionPortManager manager = ApplicationManager.Current.ExtensionPortManager;
            if (manager.GetExtensionPort<IViewControllerExtenderContract>() == null)
            {
                ExtensionPortBase<IViewControllerExtenderContract> port;
                port = new ExtensionPortBase<IViewControllerExtenderContract>();
                manager.RegisterExtensionPort<IViewControllerExtenderContract>(port);
            }
        }

        #region IViewController Members

        public IView CurrentView { get; set; }

        public event EventHandler CurrentViewChanged;

        public IView OpenView(IModel model)
        {
            IExtensionPortManager manager;
            manager = ApplicationManager.Current.ExtensionPortManager;

            IExtensionPort<IViewControllerExtenderContract> port;
            port = manager.GetExtensionPort<IViewControllerExtenderContract>();

            foreach (IExtender<IViewControllerExtenderContract> extender in port.Extenders)
            {
                IViewControllerExtenderContract contract;
                contract = extender.GetImplementation();

                if (contract != null) contract.GetView(model);
            }
            return null;
        }

        #endregion
    }
}
